﻿
PhilHealth = {
    PhUpdatePopUpId: '',
    CurrentRow: null,
    OnAddPhClick: function () {
        $('#btnAddPH').live("click", function (e) {
            e.preventDefault();
            var id = $(this).attr("id");
            PhilHealth.PhUpdatePopUpId = id;

            PopUpDialog.UrlDialog("PhilHealth", 420, 280, true, "../PopupBoxes/PhilHealthDialogBox.aspx?id=0", id);           
        });
    }, OnUpdatePhClick: function () {
        $('table#PhilHealthtbl .btnUdpate').live("click", function (e) {
            e.preventDefault();
            var id = $(this).attr("data-id");
            PhilHealth.CurrentRow = $(this).closest("tr");
            PhilHealth.PhUpdatePopUpId = id;

            PopUpDialog.UrlDialog("PhilHealth", 420, 280, true, "../PopupBoxes/PhilHealthDialogBox.aspx?id=" + id, id);
        });
    },
    OnDeletePhClick: function () {
        $('table#PhilHealthtbl .btnDelete').live("click", function (e) {
            e.preventDefault();
            if (confirm('Are you sure you want to delete item?')) {
                var id = $(this).attr("data-id");
                var json = JSON.stringify({ Id: id });
                PhilHealth.CurrentRow = $(this).closest("tr");
                $.ajax({
                    type: "POST",
                    url: "../Webservices/UtilitiesWebsService.asmx/DeletePH",
                    data: json,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        var response = eval('(' + data.d + ')');
                        if (response.Success) {
                            PhilHealth.CurrentRow.remove();                            
                        }
                    }
                });

            }
        });
    },
    SetRowData: function (Obj) {
        if (Obj.IsAdded) {
            location.reload(true);
        }
        var id = Obj.PHItem.Id;
        var startRange = Obj.PHItem.StartRange;
        var endRange = Obj.PHItem.EndRange;
        var base = Obj.PHItem.Base;
        var total = Obj.PHItem.Total;

        PhilHealth.CurrentRow.find("td").eq(0).html(id);
        PhilHealth.CurrentRow.find("td").eq(1).html(startRange);
        PhilHealth.CurrentRow.find("td").eq(2).html(endRange);
        PhilHealth.CurrentRow.find("td").eq(3).html(base);
        PhilHealth.CurrentRow.find("td").eq(4).html(total);
    }
}

$(document).ready(function () {
    PhilHealth.OnAddPhClick();
    PhilHealth.OnUpdatePhClick();
    PhilHealth.OnDeletePhClick();    
});